﻿using System.Windows.Controls;
using System.Windows.Navigation;
using GraphMyCode.Client.ViewModels;
using GraphMyCode.Client.Views;

namespace GraphMyCode.Client
{
	public partial class MainPage
	{
		public MainPage()
		{
			InitializeComponent();
			DataContext = new GraphMapViewModel();

			ContentFrame.Navigated += new NavigatedEventHandler(ContentFrame_Navigated);
		}

		void ContentFrame_Navigated(object sender, NavigationEventArgs e)
		{
			if(e.Content is GraphMapPage)
			{
				((GraphMapPage) (e.Content)).Rescale(ActualWidth, ActualHeight);
			}
		}

		private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
		{
			e.Handled = true;
			ChildWindow errorWin = new ErrorWindow(e.Uri);
			errorWin.Show();
		}
	}
}